package org.ratingviewer.ui.action;

import javax.swing.*;

import org.ratingviewer.resources.Resources;

public abstract class AbstractResourcedAction extends AbstractAction {

	private static final long serialVersionUID = 1L;

	public AbstractResourcedAction(String itemName, JComponent shortcutHandler) {
		if (itemName == null)
			throw new IllegalArgumentException("ItemName can't be null.");

		Resources resources = Resources.getInstance();
		resources.fillActionFrom(itemName, this);

		Object key = null;
		if (shortcutHandler != null && (key = getValue(ACCELERATOR_KEY)) instanceof KeyStroke) {
			shortcutHandler.registerKeyboardAction(this, (KeyStroke) key,
					JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
		}
	}

	public AbstractResourcedAction(String itemName) {
		this(itemName, null);
	}

}
